package com.gtgj.widget;

import com.gtgj.widget.util.DataUtils;
import com.gtgj.widget.util.HttpUtils;
import ohos.aafwk.ability.AbilityPackage;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import ohos.utils.zson.ZSONObject;

public class MyApplication extends AbilityPackage {
    private HiLogLabel TAG = new HiLogLabel(HiLog.DEBUG, 0x0, MyApplication.class.getName());

    @Override
    public void onInitialize() {
        super.onInitialize();
        HttpUtils.reqDate(this, (success, content) -> {
            HiLog.debug(TAG, "content is " + content);
            if (success) {
                ZSONObject data = ZSONObject.stringToZSON(content).getZSONObject("data");
                DataUtils.saveDate(getApplicationContext(), "beforeDay", data.getIntValue("grabCalendarDaysBeforeBuyDate"));
                DataUtils.saveDate(getApplicationContext(), "afterDay", data.getIntValue("grabCalendarDaysAfterBuyDate"));
            }
        });
    }
}
